layui.use(['form', 'layer', 'table'], function () {
        const form = layui.form,
            layer = parent.layer === undefined ? layui.layer : top.layer,
            $ = layui.jquery,
            table = layui.table;

        //列表
        const tableIns = table.render({
            elem: '#list',
            url: $.cookie("tempUrl") + 'SysDoctorCase/selectListByDoctorId',
            where: {
                doctorId: $.cookie("doctorId")
            },
            method: "GET",
            // request: {
            //     pageName: 'pageNum' //页码的参数名称，默认：page
            //     , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            // },
            response: {
                statusName: 'code' //数据状态的字段名称，默认：code
                , statusCode: 200 //成功的状态码，默认：0
                , msgName: 'msg' //状态信息的字段名称，默认：msg
                , countName: 'totalElements' //数据总数的字段名称，默认：count
                , dataName: 'data' //数据列表的字段名称，默认：data
            },
            cellMinWidth: 95,
            // page: true,
            height: "full-25",
            // limits: [5, 10, 15, 20, 25],
            // limit: 15,
            id: "dataTable",
            toolbar: '#toolbarDemo',
            defaultToolbar: [],
            cols: [[
                {field: 'menberName', title: '患者姓名', minWidth: 100, align: 'center'},
                {
                    field: 'menberSex', title: '患者性别', width: 100, align: 'center', templet: function (d) {
                        switch (d.menberSex) {
                            case 1:
                                return '男';
                            case 2:
                                return '女';
                        }
                    }
                },
                {field: 'menberAge', title: '患者年纪', minWidth: 100, align: 'center'},
                {field: 'disease', title: '疾病', minWidth: 100, align: 'center'},
                {field: 'cbzd', title: '初步诊断', minWidth: 100, align: 'center'},
                {title: '操作', width: 145, templet: '#userListBar', fixed: "right", align: "center"}
            ]]
        });

        //头工具栏事件
        table.on('toolbar(test)', function (obj) {
            const checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'add_btn':
                    const index = layui.layer.open({
                        title: "创建案例",
                        type: 2,
                        area: ["500px", "450px"],
                        content: "archives01By02Add.html",
                        shadeClose: true,
                        success: function () {

                        }
                    });
                    layui.layer.full(index);
                    window.sessionStorage.setItem("index", index);
                    //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
                    $(window).on("resize", function () {
                        layui.layer.full(window.sessionStorage.getItem("index"));
                    });
                    break;
            }
        });

        //列表操作
        table.on('tool(test)', function (obj) {
            const layEvent = obj.event,
                data = obj.data;
            switch (layEvent) {
                case 'edit'://编辑
                    $.cookie('tempId', data.id, {path: '/'});
                    const index = layui.layer.open({
                        title: "编辑案例",
                        type: 2,
                        content: "archives01By02Upd.html",
                        success: function (layero, index) {
                        }
                    });
                    layui.layer.full(index);
                    window.sessionStorage.setItem("index", index);
                    //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
                    $(window).on("resize", function () {
                        layui.layer.full(window.sessionStorage.getItem("index"));
                    });
                    break;
                case 'del'://删除
                    layer.confirm('确定删除此案例？', {icon: 3, title: '提示信息'}, function (index) {
                        $.ajax({
                            url: $.cookie("tempUrl") + "SysDoctorCase/deleteById?id=" + data.id,
                            type: "DELETE",
                            success: function (result) {
                                layer.msg("删除成功");
                                // window.location.href = "informationList.html";
                            }
                        });
                        obj.del(); //删除对应行（tr）的DOM结构，并更新缓存
                        // tableIns.reload();
                        layer.close(index);
                    });
                    break;
            }
        });
    }
);
